import {defineStore} from "pinia";
import store from "../data";
export const useDefaultStore = defineStore('default', {
    state: () => ({
        Token: '',
    }),
    getters: {
        tokenExpirationTime: (state): number => {
            try {
                if (state.Token != '') {
                    let ss = state.Token.split(".")
                    if (ss.length >= 2) {
                        let tk = JSON.parse(atob(ss[1]))
                        return tk.exp || 0
                    }
                }
                return 0
            } catch (e) {
                console.log(e)
                return 0
            }
        }
    },
    actions: {
        updateToken(token: string) {
            this.Token = token
            window.localStorage.setItem("token", token)
        }
    }
})

export function getDefaultStore() {
    return useDefaultStore(store)
}